{% extends 'extends/nav_front_all_.html' %}

{% block main %}
     <div class="container py-5">
        <div class="card">
            <div class="card-header">
                <h4>评论管理</h4>
            </div>
            <div class="card-body">
                <div class="container mt-4">
                    <div class="row">
                        <div class="col-md-12">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>帖子</th>
                                        <th>评论</th>
                                        <th>日期</th>
                                        <th>删除</th>
                                    </tr>
                                </thead>
                                <tbody id="comments-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
     </div>

<script>

    function DeleteEvent(url,cid){
        Fetch(url,'delete',{cid:cid},async res => {
            await Flash(res.msg)
            Redirect()
        })
    }

onUrlsReady(urls => {
    Fetch(urls.info.mycomments, 'get', {}, res => {
        if (res.status === 'success') {
            res.data.comments.forEach(comment => {
                var post_url = urls.page.front.blogdetail.replace('0', comment.pid)
                const but=`<a class="btn btn-sm btn-primary" onclick="DeleteEvent('${urls.service.commentorcancel}',${comment.pid})">删除</a>`
                row=table_item(
                    `<a href="${post_url}">${comment.pid}</a>`,
                    `${comment.content}`,
                    `${comment.time}`,
                    but
                )
                Element_('comments-body').insertAdjacentHTML('beforeend', row);
            });
        }
    });
});


</script>

{% endblock %}
